// 导入request
import http from "@utils/request";
import type { IRes } from "@interface";

interface IImageCodeData extends IRes {
  data: {
    redirectUri: string;
    appid: string;
    scope: string;
    state: string;
  };
}
// 获取图片验证码
export const getImageCode = (phone: string) =>
  http.post<IImageCodeData>("/xlx-sso/user/getImageCode", { phone });

interface IVerifyImageCodeData extends IRes {
  data: boolean;
}
// 校验滑块图形验证并发送验证码
export const verifyImageCode = (movePosX: string, phone: string) =>
  http.post<IVerifyImageCodeData>("/xlx-sso/user/verifyImageCode", {
    movePosX,
    phone,
  });

interface ILoginVerificationData extends IRes {
  data: {
    token: string;
    isNew: boolean;
  };
}
// 验证码登录
export const loginVerification = (phone: string, verificationCode: string) =>
  http.post<ILoginVerificationData>("/xlx-sso/user/loginVerification", {
    phone,
    verificationCode,
  });

interface ILoginParamData extends IRes {
  data: {
    redirectUri: string;
    appid: string;
    scope: string;
    state: string;
  };
}

// 微信登录-获取微信参数
export const getLoginParam = () =>
  http.get<ILoginParamData>("/xlx-sso/oauth/wechat/getLoginParam");

export interface IuserLogin {
  user: {
    created: null; //创建时间
    updated: null; //更新时间
    id: number;
    mobile: string; //用户手机号
    password: null;
  };
  token: string;
}
interface IUserLoginData extends IRes {
  data: IuserLogin;
}
//账号密码登录
export const userLogin = (mobile: string, password: string) =>
  http.post<IUserLoginData>("/xlx-sso/user/login", {
    mobile,
    password,
  });
